﻿#region Copyright (c) 2000-2008 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{       AgDataGrid                                 }
{                                                                   }
{       Copyright (c) 2000-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2008 Developer Express Inc.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Controls;
#if !SL
using DevExpress.Wpf.Core.Native;
using DevExpress.Wpf.Utils.Native;
#else
#endif
using System.Collections;
#if !SL
namespace DevExpress.Wpf.Core {
#else
namespace DevExpress.AgDataGrid.Utils {
#endif
	public class StackVisibleIndexPanel : OrderPanelBase {
		protected override Size MeasureSortedChildrenOverride(Size availableSize, IList<UIElement> sortedChildren) {
			availableSize = SizeHelper.CreateSize(double.PositiveInfinity, SizeHelper.GetSecondarySize(availableSize));
			double defineSize = 0;
			double secondarySize = 0;
			foreach (UIElement child in sortedChildren) {
				child.Measure(availableSize);
				secondarySize = Math.Max(secondarySize, SizeHelper.GetSecondarySize(child.DesiredSize));
				defineSize += SizeHelper.GetDefineSize(child.DesiredSize);
			}
			return SizeHelper.CreateSize(defineSize, secondarySize);
		}
		protected override Size ArrangeSortedChildrenOverride(Size finalSize, IList<UIElement> sortedChildren) {
			Rect finalRect = new Rect(new Point(), finalSize);
			double defineSize = 0;
			foreach (UIElement child in sortedChildren) {
				Point location = SizeHelper.CreatePoint(SizeHelper.GetDefinePoint(finalRect.Location()) + defineSize, SizeHelper.GetSecondaryPoint(finalRect.Location()));
				finalRect.X = location.X;
				finalRect.Y = location.Y;
				defineSize = SizeHelper.GetDefineSize(child.DesiredSize);
				Size size = SizeHelper.CreateSize(defineSize, Math.Max(SizeHelper.GetSecondarySize(finalRect.Size()), SizeHelper.GetSecondarySize(child.DesiredSize)));
				finalRect.Width = size.Width;
				finalRect.Height = size.Height;
				child.Arrange(finalRect);
			}
			return finalSize;
		}
	}
	public static class RectExtension {
		public static Point Location(this Rect rect) {
			return new Point(rect.X, rect.Y);
		}
		public static Size Size(this Rect rect) {
			return new Size(rect.Width, rect.Height);
		}
	}
}
